#!/bin/sh
# Load functions and variables
. /usr/bin/common
cd /root/android-sandcastle/

# Show ASCII art
android_logo

cat << "EOF"
Connect a jailbroken iDevice with an internet connection

The keyboard layout is in American Qwerty.
Your iDevice's default password is alpine.

EOF

# Ask if the user uses odysseyra1n or checkra1n and set port to 22 for odysseyra1n or 44 for checkra1n
until [ "$port" = 22 ] || [ "$port" = 44 ]; do
	prompt 'Are you using odysseyra1n or checkra1n [O/c] ' jailbreak
	case "$jailbreak" in
		[oO][dD][yY][sS][sS][eE][yY][rR][aA][1iI][nN]|[oO])
			port='22' ;;
		[cC][hH][eE][cC][kK][rR][aA][1iI][nN]|[cC])
			port='44' ;;
		*)
			echo 'Invalid input!' ;;
	esac
done

IPROXY=$(iproxy 28605 "$port" >/dev/null 2>&1 & echo $!)

clear

blue_echo 'Copying the setup script to your device...'
if scp -qP28605 -o "StrictHostKeyChecking no" -o "UserKnownHostsFile=/dev/null" isetup root@127.0.0.1:/tmp/setup.sh; then
	done_echo 'Done copying the setup script to your device.'
else
	failed_echo 'Failed to copy the setup script to your device.'
fi

blue_echo 'Downloading NAND...'
if ssh -qp28605 -o "StrictHostKeyChecking no" -o "UserKnownHostsFile=/dev/null" root@127.0.0.1 "chmod 755 /tmp/setup.sh && /tmp/setup.sh"; then
	done_echo 'Done downloading NAND.'
	echo 'Select "Start Android" to boot into Android'
	enter_to_quit
	/usr/bin/menu_projectsandcastle
else
	failed_echo 'Failed to download NAND.'
fi
